import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/Welcome.vue'
import Users from '../components/user/Users.vue'
import Roles from '../components/roles/Roles.vue'
import Rights from '../components/roles/Rights.vue'
import Tab from '../components/user/tab.vue'
import Goods from '../components/goods/goodsList.vue'
import cate from '../components/goods/cate.vue'
import params from '../components/goods/params.vue'
import orders from '../components/orders.vue'
import reports from '../components/reports.vue'
Vue.use(VueRouter)
const routes = [{
    path: '/',  component: Login
  },
  {
    path: '/login',  component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [
      { path: '/welcome',component: Welcome },
      { path: '/users',component: Users },
      { path: '/tab',component: Tab },
      {path: '/roles',  component: Roles},
      {path: '/rights',  component: Rights},
      {path: '/goods',  component: Goods},
      {path: '/categories',  component: cate},
      {path: '/params',  component: params},
      {path: '/orders',  component: orders},
      {path: '/reports',  component: reports}
    ]
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
      if (to.path == '/login') next()
      const tokenStr = window.sessionStorage.getItem('token')
      if(!tokenStr) return next('/login')
      next()
    })
export default router

